#include <stdio.h>
#include <string.h>

struct student
{
    char name[100];
    int age;
};

//一个结构体变量的成员
//总是以最大的那个元素作为对其单位的
struct A
{
    long b1;
    long long b2;
    int  a1;
    char a3;
    char a2;
    char a4;
    char a5;
    char a6;
};

struct B
{
    char a1;
    short a2;
    char a3;
    int a4;
};


struct C
{
    char a1;
    char a3;
    short a2;
    int a4;
};











int main0()
{
    struct student st;//定义了一个student类型的结构体变量，名字叫st

    st.age = 20;
    strcpy(st.name, "刘德华");
    printf("name = %s, age = %d\n", st.name, st.age);
    return 0;
}

int main1()
{
    //struct student st = {"周星驰", 40};//定义结构体变量的时候，同时初始化成员变量的值
    //struct student st = { 0 };
    //struct student st = {"周杰伦"};
    struct student st = {.age = 30, .name = "张学友"};
    printf("name = %s, age = %d\n", st.name, st.age);
    return 0;
}

int main2()
{
    struct A a;
    printf("%lu\n", sizeof(a));
    return 0;
}

int main3()
{
    struct B a = {1,2,3,4};
    printf("%p\n", &a);
    return 0;
}

int main4()
{
    struct C a = {1,2,3,4};
    printf("%p\n", &a);
    return 0;
}




//如果结构体成员出现数组，
//那么是以数组的具体每个成员作为对齐标准
struct D
{
    char a[10];
    char b;
};


struct E
{
    char a1;
    short a2;
    int a3;
};


int main9()
{
    struct D d = {};
    printf("%lu\n", sizeof(d));
    char *s = (char *)&d;
    s[0] = 'a';
    s[1] = 'b';
    s[10] = 'c';
    printf("%s\n", d.a);
    printf("%c\n", d.b);
    printf("%p, %p\n", &d, d.a);

    struct E e = {1,2,3};
    s = (char *)&e;
    s[1] = 10;
    
    printf("%p\n", &e);


    return 0;
}


struct F
{
    char a1;
    short a2;
    int a3;
    short a4;
    char a5;
};

int main()
{
    struct F f = {};
}




